package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.HangSaleBill;
import cn.wolfcode.crm.domain.SaleOut;
import cn.wolfcode.crm.query.JSONResult;
import cn.wolfcode.crm.service.IHangSaleBillService;
import cn.wolfcode.crm.service.imp.HangSaleBillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("sale")
public class SaleController {

    @Autowired
    private IHangSaleBillService hangSaleBillService;

    @RequestMapping("view")
    public String view(){
        return "cashierBill";
    }


    /*挂单*/
    @RequestMapping("hangBill")
    @ResponseBody
    public JSONResult hangBill(HangSaleBill hangSaleBill){
        JSONResult result = new JSONResult();
        try{
            hangSaleBillService.save(hangSaleBill);
        }catch (Exception e){
            e.printStackTrace();
            result.mark(e.getMessage());
        }
        return result;
    }

    /*挂单列表*/
    @RequestMapping("hangBillList")
    @ResponseBody
    public List<HangSaleBill> hangBillList(){
        return hangSaleBillService.selectAll();
    }
    @RequestMapping("delete")
    @ResponseBody
    public JSONResult delete(Long id){
        JSONResult result = new JSONResult();
        try{
            hangSaleBillService.deleteByPrimaryKey(id);
        }catch (Exception e) {
            e.printStackTrace();
            result.mark(e.getMessage());
        }
        return result;
    }

    /*付款操作*/
    @RequestMapping("payment")
    @ResponseBody
    public JSONResult payment(SaleOut saleOut){
        JSONResult result = new JSONResult();
        try{
            hangSaleBillService.payment(saleOut);
        }catch (Exception e) {
            e.printStackTrace();
            result.mark(e.getMessage());
        }
        return result;
    }

}
